/*
https://leetcode.cn/problems/building-boxes/solutions/2031813/mei-xiang-ming-bai-yi-ge-dong-hua-miao-d-8vbe/
 */
public class Solution1739 {
    public int minimumBoxes(int n) {
        int x = (int) Math.cbrt(6L * n);
        int max = (int) ((long) x * (x + 1) * (x + 2) / 6);
        if (max>n){
            x--;
            max = (int) ((long) x * (x + 1) * (x + 2) / 6);
        }
        return x*(x+1)/2+(int)Math.ceil((-1+Math.sqrt(1+8*(n-max)))/2);
    }

    public static void main(String[] args) {
        System.out.println(new Solution1739().minimumBoxes(15));
    }
}
